new Vue({
  el: '#app',
  data() {
    return {
      form: {
        Article_Name: '',
        page: 1,			//页数
        limit: 10,
        Enterprise_Info_SerialNumber: $.cookie('enterprise'),
        isVague: true,
      },
      formData: {},
      tableData: [
      ],
      tableData2: [],
      //表格数据
      total: 1,
      dialogForm: false,
      title: '',
      multipleSelection: [],
      // xiangqing:[]
    }
  },
  mounted() {
    this.getList(this.form)
    // console.log(DomainName);
  },
  methods: {
    onSerach() {				//查询方法
      this.getList(this.form)
    },
    addContract() {
      console.log("跳转")
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form)
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form)
    },
    getList(data) {
      let _this = this
      $.ajax({
        type: 'POST',
        data,
        url: DomainName + '/getIntegralShopAllAction?token=' + $.cookie("token"),
        success: function (data) {
          console.log('data', data);
          _this.tableData = data.tableData;
          // _this.total = Number(data.total);
          console.log(_this.tableData)
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });
    },
    expandChange(row) {
      console.log('详情', row)
      let _this = this;
      $.ajax({
        url: DomainName + '/getInquiryIDAction?token=' + $.cookie('token'),
        type: 'POST',
        data: {
          Data: 'integral_unitprice_detail',
          Primary_Key: row.Integral_Unit_Price_SerialNumber,
          Primary_Key_Name: 'Integral_Unit_Price_SerialNumber'
        },
        success: function (res) {
          console.log('888', res)
          row.form = res
          console.log(row.form)
        }
      })
    },
    addEnterprise() {
      console.log('增加')
      window.location.href = './Add.html'
    },
    showMember(Integral_Unit_Price_SerialNumber) {
      sessionStorage.setItem("Integral_Unit_Price_SerialNumber", Integral_Unit_Price_SerialNumber)
      window.location.href = './show.html?Integral_Unit_Price_SerialNumber=' + Integral_Unit_Price_SerialNumber
    },
    editMember(Integral_Unit_Price_SerialNumber) {
      sessionStorage.setItem("Integral_Unit_Price_SerialNumber", Integral_Unit_Price_SerialNumber)
      window.location.href = './Edit.html?Integral_Unit_Price_SerialNumber=' + Integral_Unit_Price_SerialNumber
    },
    onExcel() {
      /* generate workbook object from table */
      //  .table要导出的是哪一个表格
      var wb = XLSX.utils.table_to_book(document.querySelector("#out-table"));
      /* get binary string as output */
      var wbout = XLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array"
      });
      try {
        //  name+'.xlsx'表示导出的excel表格名字
        saveAs(
          new Blob([wbout], {
            type: "application/octet-stream"
          }),
          "销售价格单" + ".xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
    deletMember(Primary_Key) {
      this.$confirm('此操作将删除该系列, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        this.delete(Primary_Key);
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    delete(Primary_Key) {
      const _this = this
      $.ajax({
        url: DomainName + '/DeleteAction?token=' + $.cookie('token'),
        type: 'POST',
        data: {
          TableName: 'integral_unitprice',
          Primary_Key,
          Primary_Key_Name: 'Integral_Unit_Price_SerialNumber',
        },
        success: function (res) {
          console.log('删除', res)
          _this.$message({
            type: 'success',
            message: '删除成功!'
          });
          _this.getList(_this.form);
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    },
    // 子表删除
    deletMember2(Primary_Key) {
      this.$confirm('此操作将删除该系列, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        this.del(Primary_Key);
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    del(Primary_Key) {
      const _this = this
      $.ajax({
        url: DomainName + '/DeleteAction?token=' + $.cookie('token'),
        type: 'POST',
        data: {
          TableName: 'integral_unitprice_detail',
          Primary_Key,
          Primary_Key_Name: 'Integral_Unit_Price_Detail_SerialNumber',
        },
        success: function (res) {
          console.log('删除', res)
          _this.$message({
            type: 'success',
            message: '删除成功!'
          });
          _this.getList(data)
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    },











    // deletMember2(row) {
    //   console.log('子表删除',row)
    //   const _this = this;
    //   let Primary_Key_Name = "Integral_Unit_Price_Detail_SerialNumber";
    //   let Primary_Key = row.Integral_Unit_Price_Detail_SerialNumber;
    //   this.$confirm('此操作将删除该商品信息, 是否继续?', '提示', {
    //     confirmButtonText: '确定',
    //     cancelButtonText: '取消',
    //     type: 'warning',
    //   }).then(() => {
    //     $.ajax({
    //       url: DomainName + '/getInquiryIDOriginal?token=' + $.cookie('token'),
    //       type: 'POST',
    //       data: {
    //         Primary_Key_Name,
    //         Primary_Key,
    //         Data: "integral_unitprice_detail",
    //       },
    //       error: function (array) {
    //         console.log(array);
    //         _this.$message.error("删除失败，请稍后再试")
    //       },
    //       complete: function (XMLHttpRequest) {
    //         _this.loading = false
    //         if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
    //           window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
    //         }
    //       },
    //       success: function (res) {
    //         console.log('删除子表',res)
    //         _this.Delete(res);
    //       }
    //     })
    //   }).catch(() => {
    //     this.$message({
    //       type: 'warning',
    //       message: '已取消删除'
    //     });
    //   });
    // },
    // //删除
    // Delete(row) {
    //   console.log(row)
    //   const _this = this;
    //   let rowData = [];
    //   // 判断 row 的类型
    //   if (Array.isArray(row)) {
    //     // 如果是数组，则取第一个元素作为 rowData
    //     rowData = [...row];
    //   } else {
    //     // 否则，直接使用 row 作为 rowData
    //     rowData.push(
    //       row
    //     );
    //   }
    //   rowData.forEach((item) => {
    //     item.Row_Status = '1'
    //   })
    //   let data = {
    //     Data: JSON.stringify({
    //       Modify: { integral_unitprice_detail: rowData }
    //     })
    //   };
    //   $.ajax({
    //     url: DomainName + '/getEditAction?token=' + $.cookie('token'),
    //     type: 'POST',
    //     data,
    //     error: function (array) {
    //       console.log(array);
    //       _this.$message.error("删除失败，请稍后再试")
    //     },
    //     complete: function (XMLHttpRequest) {
    //       _this.loading = false
    //       if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
    //         window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
    //       }
    //     },
    //     success: function (res) {
    //       if (res.Status == 'success') {
    //         _this.$message({
    //           type: 'success',
    //           message: '删除成功!'
    //         });
    //       }
    //     }
    //   })
    // }
  },
})